﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using clf.weighing.entity;

namespace weighing
{
    /// <summary>
    /// Ic 读卡器的接口
    /// </summary>
    public interface IICReader
    {
        bool IsOpen();
        bool SetAddr(byte addr);
        int GetAddr(out byte addr);
        bool SetBaudRate(byte addr);
        bool Connect(String com, int baudRate);
        bool DisConnect();
        /// <summary>
        /// 读取 卡号 或者 EPC号,
        /// </summary>
        /// <param name="addr">读写器地址,设备号</param>
        /// <returns></returns>
        int GetCardNo(byte addr, out string number);
        /// <summary>
        /// 读取M1卡卡号
        /// </summary>
        /// <param name="addr">读写器地址,设备号</param>
        /// <returns></returns>
        int ReaderM1Number(byte addr,out string number);
        /// <summary>
        /// 读取M1 卡的类型
        /// </summary>
        /// <param name="addr">读写器地址,设备号</param>
        /// <returns></returns>
        string ReaderM1Type(byte addr);
        int ReaderData(byte addr, byte block, byte beep, out string data);

        int ReaderData(byte addr, byte block, byte beep, out byte[] datas);
        int WriterData(byte addr, byte block, byte[] datas, byte beep);

        string GetErrorInfo(int errCode);
        /// <summary>
        ///  读取车辆信息 id? carnumber driverName phone traeWeight
        /// </summary>
        /// <returns></returns>
        CarInfo ReadCarinfo(out string errorMsg);

        /// <summary>
        /// 将车辆信息写入到 IC卡中
        /// </summary>
        /// <param name="carInfo"></param>
        /// <param name="errorMsg">错误信息 无错误 主 empty</param>
        /// <returns> >=0 ok  -1 error</returns>
        int WriteCarInfo(CarInfo carInfo, out string errorMsg);
        /// <summary>
        /// 将磅单信息写入到 IC卡中
        /// </summary>
        /// <param name="carInfo"></param>
        /// <param name="errorMsg">错误信息 无错误 主 empty</param>
        /// <returns> >=0 ok  -1 error</returns>
        int WriteWeighingBill(WeighingBill bill, out string errorMsg);

        /// <summary>
        /// 读取 IC卡中磅单信息
        /// </summary>
        /// <param name="errorMsg">错误信息 无错误  empty</param>
        /// <returns> null  or WeighingBill</returns>
        WeighingBill ReadWeighingBill(out string errorMsg);
        /// <summary>
        /// 读取发货单信息
        /// </summary>
        /// <param name="errMsg">错误信息 无错误  empty</param>
        /// <returns>null or WeighingBill </returns>
        SendCarBill ReadSendCarBill(out string errMsg);

        /// <summary>
        /// 单位 毫秒
        /// </summary>
        /// <param name="time"></param>
        void Beep(short time = 100);
    }
}
